import apis from '../../http/apis/index.js'
export default {
    namespaced: true,
    state: {
        //初始列表数据
        powerData: [
            // {
            //     poweerplantScore: "17.5",
            //     powerplanName: "小熊猫充电站",
            //     powerplantAddress: "无人区",
            //     powerplantAlternatingNumber: 21,
            //     powerplantCocurrentNumber: 20,
            //     powerplantCoordinate: {
            //         latitude: 30.6563,
            //         longitude: 104.028168
            //     },
            //     powerplantId: 1,
            //     powerplantImage: "http://119.23.75.195:9000/services/f3cb8826-b78a-4ddd-9a20-e83c109de67c.png",
            //     powerplantIntroduce: "8:00-00:00",
            //     powerplantPhone: "15654865355",
            //     stationPrice: 2,
            //     userId: 1,
            // }
        ],
        powerOneData: {},
        bridge: [],
        flag:null
    },
    mutations: {
        setpowerData(state, data) {
            state.powerData = data
        },
        setpowerOneData(state, data) {
            state.powerOneData = data
        },
        setbridge(state, data) {
            state.bridge = data
        },
        setorderData(state,data){
            state.flag=data
        }
    },

    actions: {
        //context
        async getPowerData(context, params) {
            const data = await apis.getpower()
            if (data.code == 200) {
                context.commit('setpowerData', data.data);
            }
        },
        async getOnePowerData(context, params) {
            const data = await apis.getOnePower(params)
            if (data.code == 200) {
                context.commit('setpowerOneData', data.data)
            }
        },
        async getByIdBridge(context, params) {
            const data = await apis.getByPowerplant(params)
            if (data.code == 200) {
                context.commit('setbridge', data.data)
            }
        },
        //根据定位经纬度查询附近门店
        async getridge(context, params) {
            const data = await apis.longitudeAndLatitudeParam(params)
            if (data.code == 200) {
                context.commit('setpowerData', data.data.searchHits)
            }
        },
        //新增电站订单
        async addorder(context, params) {
            const data = await apis.addPowerplantOrderParam(params)
            console.log(data.flag);
            if (data.code == 200) {
               context.commit("setorderData",data.flag)
            }
        },
        

    },
}
